<template>
  <div>
    <CustomTable
      ref="table"
      :showAlert="false"
      :showSelection="false"
      :columns="xypjColumns"
      :loading="load"
      @change="onTableChange"
      :dataSource="pageData"
      :style="{ marginTop:'20px', height: '540px' }"
    >
     <template slot="xh" slot-scope="text, record, index">
        {{((pageFilter.pageNo - 1) * pageFilter.pageSize +(index + 1))>9?(pageFilter.pageNo - 1) * pageFilter.pageSize +(index + 1) :'0' + (index + 1) }}
      </template>
      <template slot="dwlb" slot-scope="text">
        <span>{{ dictText('单位类别',text) }}</span>
      </template>
      <template slot="creditLevel" slot-scope="text">
        <span>{{ dictText('信用等级类别',text) }}</span>
      </template>
      <template slot="dateBf" slot-scope="record">
        <span v-if="record!=='' && record!==null">{{ moment(record).format("YYYY-MM-DD") }}</span>
      </template>
      <template slot="effictivedateto" slot-scope="record">
        <span v-if="record!=='' && record!==null">{{ moment(record).format("YYYY-MM-DD") }}</span>
      </template>
    </CustomTable>
  </div>
</template>

<script>
import emv from "@/views/center/emptyVue.vue";
import api from '@/api/index'
export default {
  props: {
    codeZzjg: {
      type: String
    }
  },
  data() {
    return {
      load: false,
      xypjColumns: [
        {
          title: "序号",
          dataIndex: "xh",
          key: "xh",
          width:80,
          scopedSlots: { customRender: "xh" }
        },
        {
          title: "单位类别",
          dataIndex: "dwlb",
          key: "dwlb",
          scopedSlots: { customRender: "dwlb" }
        },
        {
          title: "信用等级",
          dataIndex: "creditLevel",
          key: "creditLevel",
          scopedSlots: { customRender: "creditLevel" }
        },

        {
          title: "证书编号",
          dataIndex: "idZs",
          key: "idZs",
          ellipsis: true,
        },
        {
          title: "评价单位",
          dataIndex: "unitPj",
          key: "unitPj",
          ellipsis: true,
        },
        {
          title: "颁发日期",
          dataIndex: "dataBf",
          key: "dataBf",
          scopedSlots: { customRender: "dateBf" },
          ellipsis: true,
        },
        {
          title: "有效期至",
          dataIndex: "effictivedateto",
          key: "effictivedateto",
          ellipsis: true,
          scopedSlots: { customRender: "effictivedateto" }
        }
      ],
      pageData: [],
      pageFilter: {
        pageNo: 1,
        pageSize: 10,
        isPass:true,
      },
      dictDW:undefined
    };
  },
  created() {
    this.pageFilter.idZzjg = this.codeZzjg;
    this.refreshTable();
    this.dictList()
  },
  methods: {
    //字典获取
    dictList(){
      api.get_dict().then(ser => {
        this.dictDW = ser
        console.log(this.dictDW)
      })
    },
    dictText(val,text){
      let list = []
      var arr = (text || '').split(`,`)
      console.log(arr)
      for(let item of arr){
        for(let index of this.dictDW){
          if(item === index.dictValue && val === index.dictType){
            list.push(index.dictLabel)
          }
        }
      }
      if(list.length !== 0){
        console.log(list)
        return list.toString()
      } else {
        console.log(text)
        return text
      }
    },
    onTableChange(pageFilter) {
      this.pageFilter = { ...this.pageFilter, ...pageFilter };
      this.refreshTable();
    },
    async refreshTable() {
        this.load = true;
        await api.get_credit_list(this.pageFilter) .then(res => {
          let pageNo = this.pageFilter.pageNo;
          let pageSize = this.pageFilter.pageSize;
          let records = res.rows;
          let total = res.total;
          this.pageData = {
            ...this.pageData,
            pageNo,
            records,
            pageSize,
            total
          };
          this.load = false;

        })
        .catch(err => {
          this.load = false;
        });


      },
  }
};
</script>

<style lang="less">
</style>
